const install = (Vue, vm) => {

	//创建一个方法 用来判断是否登录
	const check = async () => {
		let LoginUser = uni.getStorageSync('LoginUser') ? uni.getStorageSync('LoginUser') : {};
		if (Object.values(LoginUser) <= 0) {
			uni.showToast({
				title: '请先登陆',
				duration: 3000,
				complete: function(res) {
					uni.switchTab({
						url: '/pages/admin/index'
					});
				}
			});
			return false;
		} else {

			let result = await vm.$u.api.admin.check({
				id: LoginUser.id ? LoginUser.id : 0,
				username: LoginUser.username ? LoginUser.username : ''
			})
			if (result.code == 1) {
				uni.setStorageSync('LoginUser', result.data);
				return true;
			} else {
				uni.removeStorageSync('LoginUser');
				uni.showToast({
					title: '非法登陆',
					duration: 3000,
					complete: function(res) {
						uni.switchTab({
							url: '/pages/admin/index'
						});
					}
				});
				return false;
			}
		}
	}

	//给vue设置服务的名称
	vm.$u.auth = {
		check
	}
}

export default {
	install
};